package cn.airia.as3wplib.service.impl
{
	import cn.airia.as3wplib.cfg.Configuration;
	import cn.airia.as3wplib.rpc.BaseServiceDelegate;
	import cn.airia.as3wplib.rpc.DelegateFactory;
	import cn.airia.as3wplib.service.IMetaWeblogService;
	
	public class MetaWeblogServiceImpl implements IMetaWeblogService
	{
		private var xmlrpc_url:String = Configuration.getInstance().xmlrpcUrl;
		private var metaWeblogXmlrpc:BaseServiceDelegate;
		
		public function MetaWeblogServiceImpl()
		{
			metaWeblogXmlrpc = DelegateFactory.getDelegate(DelegateFactory.TYPE_XMLRPC,xmlrpc_url);
		}
		/**
		 * @copy cn.airia.as3wplib.service.IMetaWeblogService#newPost()
		 */
		public function newPost(blog_id:int, username:String, password:String, content:Object, publish:Boolean, retFun:Function):void
		{
			var params:Array = new Array(blog_id,username,password,content,publish);
			metaWeblogXmlrpc.invoke("metaWeblog.newPost",params,retFun);
		}
		/**
		 * @copy cn.airia.as3wplib.service.IMetaWeblogService#editPost()
		 */		
		public function editPost(post_id:int, username:String, password:String, content:Object, publish:Boolean, retFun:Function):void
		{
			var params:Array = new Array(post_id,username,password,content,publish);
			metaWeblogXmlrpc.invoke("metaWeblog.editPost",params,retFun);
		}
		/**
		 * @copy cn.airia.as3wplib.service.IMetaWeblogService#getPost()
		 */		
		public function getPost(post_id:int, username:String, password:String, retFun:Function):void
		{
			var params:Array = new Array(post_id,username,password);
			metaWeblogXmlrpc.invoke("metaWeblog.getPost",params,retFun);
		}
		/**
		 * @copy cn.airia.as3wplib.service.IMetaWeblogService#getRecentPosts()
		 */		
		public function getRecentPosts(blog_id:int, username:String, password:String, num_posts:int, retFun:Function):void
		{
			var params:Array = new Array(blog_id,username,password,num_posts);
			metaWeblogXmlrpc.invoke("metaWeblog.getRecentPosts",params,retFun);
		}
		/**
		 * @copy cn.airia.as3wplib.service.IMetaWeblogService#getCategories()
		 */		
		public function getCategories(blog_id:int, username:String, password:String, retFun:Function):void
		{
			var params:Array = new Array(blog_id,username,password);
			metaWeblogXmlrpc.invoke("metaWeblog.getCategories",params,retFun);			
		}
		/**
		 * @copy cn.airia.as3wplib.service.IMetaWeblogService#newMediaObject()
		 */		
		public function newMediaObject(blog_id:int, username:String, password:String, data:Object, retFun:Function):void
		{
			var params:Array = new Array(blog_id,username,password,data);
			metaWeblogXmlrpc.invoke("metaWeblog.newMediaObject",params,retFun);			
		}
		/**
		 * @copy cn.airia.as3wplib.service.IMetaWeblogService#deletePost()
		 */		
		public function deletePost(post_id:int, username:String, password:String, publish:Boolean, retFun:Function):void
		{
			var params:Array = new Array(null,post_id,username,password,publish);
			metaWeblogXmlrpc.invoke("metaWeblog.deletePost",params,retFun);			
		}
		/**
		 * @copy cn.airia.as3wplib.service.IMetaWeblogService#getTemplate()
		 */		
		public function getTemplate(blog_id:int, username:String, password:String, template:String, retFun:Function):void
		{
			var params:Array = new Array(null,blog_id,username,password,template);
			metaWeblogXmlrpc.invoke("metaWeblog.getTemplate",params,retFun);	
		}
		/**
		 * @copy cn.airia.as3wplib.service.IMetaWeblogService#setTemplate()
		 */		
		public function setTemplate(blog_id:int, username:String, password:String, template:String, content:Object, retFun:Function):void
		{
			var params:Array = new Array(null,blog_id,username,password,template,content);
			metaWeblogXmlrpc.invoke("metaWeblog.setTemplate",params,retFun);	
		}
		/**
		 * @copy cn.airia.as3wplib.service.IMetaWeblogService#getUsersBlogs()
		 */		
		public function getUsersBlogs(username:String, password:String, retFun:Function):void
		{
			var params:Array = new Array(null,username,password);
			metaWeblogXmlrpc.invoke("metaWeblog.getUsersBlogs",params,retFun);
		}
	}
}